/***********************************************************************************************************************************
 *    Name:	FreshFULL.sql
 *  Author: Frank Figearo — http://sqlnerd.me/ — frank@sqlnerd.me
 * Summary:	Take a fresh FULL backup if the latest one is LiteSpeed
**/
DECLARE @dbList NVARCHAR(MAX)= N'';
WITH d (backup_set_id) AS (SELECT MAX(backup_set_id) FROM msdb.dbo.backupset WHERE type = 'D' GROUP BY database_name)
SELECT @dbList+= b.database_name + N','
  FROM msdb.dbo.backupset b 
   INNER JOIN msdb.dbo.backupmediafamily m ON (b.media_set_id = m.media_set_id)
   INNER JOIN d ON (d.backup_set_id = b.backup_set_id)
  WHERE m.physical_device_name LIKE N'%.litespeed.%';
SET @dbList= LEFT(@dbList,LEN(@dbList)-1);
EXECUTE DBAdmin.BackupDBs @dbList;
GO